<template>
	<view class="">
		<!-- #ifdef H5 -->
		<view class="">
			<u-navbar title="我的群聊" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
				leftIconColor="#333" bgColor="transparent" :rightText="rigtxt" @rightClick="rights"
				@leftClick="leftClick"></u-navbar>
			<image class="indexbg"
				src="https://images.fudiemall.com/storage/default/20250411/BG77ff634c5c493fbb0cb752c7b44d86c703900c11.png"
				mode="aspectFill"></image>
		</view>
		<!-- #endif -->
		<!-- #ifdef MP-ALIPAY -->
		<image class="indexbg"
			src="https://images.fudiemall.com/storage/default/20250411/BG77ff634c5c493fbb0cb752c7b44d86c703900c11.png"
			mode="aspectFill"></image>
		<view class="custom-nav" :style="{height:titleHeight + statusBarHeight + 'px'}">
			<view class="custom_addrress"
				:style="{height: titleHeight + 'px',paddingTop: statusBarHeight+ 'px',lineHeight:titleHeight + 'px' }">
				我的群聊
			</view>
		</view>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN  -->
		<image class="indexbg"
			src="https://images.fudiemall.com/storage/default/20250411/BG77ff634c5c493fbb0cb752c7b44d86c703900c11.png"
			mode="aspectFill"></image>
		<view class="custom_box">
			<view :style="{height: statusBarHeight + 'px', backgroundColor: backgroundColor }"></view>
			<view class="custom_nav " :style="{height: titleHeight + 'px', backgroundColor: backgroundColor}">
				<image class="goback"
					src="https://images.fudiemall.com/storage/default/20250411/left1a09bc837d836f79ae700b66670bc2b280f7c972.png"
					mode="aspectFill" @click="leftClick"></image>
				<text class="f28 c3">我的群聊</text>
			</view>
		</view>
		<view :style="{height: statusBarHeight + titleHeight + 'px'}" style="width: 100%;"></view>

		<!-- #endif -->
		<view class="new_box flex_dq" v-for="item in list " :key="item.hx_group_id" @click="gochat(item.hx_group_id)">
			<view class="notice">
				<image :src="item.avatar" mode="aspectFill"></image>
				<!-- <text class="notice_txt"></text> -->
			</view>
			<view class=" flex_Z">
				<text class="f36 c3 marb">{{item.name}}</text>
				<text class="f28 c4"></text>
			</view>
		</view>
		<u-popup :show="tipShow" mode="center" @close="tipShow = false" closeable bgColor="transparent">
			<view class="prompt flex_ZC">
				<text class="f36">提示</text>
				<text class="prompt_tit">确定要创建群聊吗</text>
				<view class="prompt_ntm flex_ld_a">
					<text @click="tipShow = false">再想想</text>
					<text @click="addgroup">去创建</text>
				</view>
			</view>
		</u-popup>
		<noDatas :xxxList="list" :showMore="false"></noDatas>

	</view>

</template>

<script>
	import WebIM from "../../utils/WebIM.js"
	import {
		memberGroupList,
		isCreateGroup,
		levelAddGroup
	} from "../../api/hx.js"

	export default {
		data() {
			return {
				list: [],
				rigtxt: "",
				statusBarHeight: 0,
				titleHeight: 0,
				tipShow: false
			}
		},
		onReady() {
			// #ifdef MP-ALIPAY || MP-WEIXIN
			uni.getSystemInfo({
				success: res => {
					this.statusBarHeight = res.statusBarHeight;
					const btnInfo = uni.getMenuButtonBoundingClientRect()
					this.titleHeight = (btnInfo.top - this.statusBarHeight) * 2 + btnInfo.height
				}
			})
			// #endif

		},
		onShow() {
			this.getlist()
			this.iscan()
		},
		methods: {
			rights() {
				console.log("我点击了")
				this.tipShow = true
			},
			addgroup() {
				let that = this
				levelAddGroup().then(res => {
					if (res.code == 1) {
						that.tipShow = false
						that.iscan()
						that.getlist()
					}
					uni.$u.toast(res.msg)
				})
			},
			iscan() {
				isCreateGroup().then(res => {

					if (res.data.is_create_group == 1) {
						this.rigtxt = "➕"
					} else {
						this.rigtxt = ''
					}
					console.log(res)
				})
			},
			right() {

			},
			gochat(id) {
				console.log(id, "我带过去了")
				uni.navigateTo({
					url: "/pageDao/groupchat/groupchat?id=" + id
				})
			},
			getlist() {
				memberGroupList({}).then(res => {
					if (res.code == 1) {
						this.list = res.data
					}
				})
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.new_box {
		width: 100%;
		position: relative;
		z-index: 99;
	}

	.notice {
		position: relative;
	}

	.custom_addrress {
		font-size: 36rpx;
		font-weight: bold;
		/* #ifdef MP-ALIPAY */
		margin-left: 70rpx;
		/* #endif */
	}

	/deep/ .u-navbar__content__right__text {
		color: #FFFFFF;
		position: relative;
		z-index: 99;
	}

	/deep/.u-navbar__content {
		background: transparent;
	}
	
	/* #ifdef MP-WEIXIN */
	.custom_box {
		width: 750rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 8;
		padding-bottom: 10rpx;
		opacity: 1;
	}
	
	.indexbg {
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 460rpx;
	}
	
	.custom_nav {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 750rpx;
		font-size: 36rpx;
		z-index: 9;
		color: #FFFFFF;
	}
	/* #endif */
	.indexbg {
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 460rpx;
		z-index: 1;
	}

	.notice>image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		margin: 0 22rpx;
		margin-top: 20rpx;
	}

	.notice_txt {
		position: absolute;
		top: 4rpx;
		right: 16rpx;
		font-size: 24rpx;
		color: #ffffff;
		background: red;
		padding: 6rpx 16rpx;
		border-radius: 40rpx;
	}

	.prompt {
		width: 600rpx;
		background: #ffffff;
		margin: 0 auto;
		border-radius: 20rpx;
		padding-top: 10rpx;
		padding-bottom: 40rpx;
	}

	.prompt>text {
		margin-top: 40rpx;
	}

	.prompt_tit {
		margin: 0 30rpx;
		font-size: 28rpx;
		color: #666666;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.prompt_ntm {
		width: 100%;
		font-size: 30rpx;
		margin-top: 50rpx;
	}

	.prompt_ntm>text:nth-child(1) {
		width: 200rpx;
		height: 72rpx;
		line-height: 72rpx;
		text-align: center;
		background: #F2F2F2;
		border-radius: 40rpx;
		color: #333333;
	}

	.prompt_ntm>text:nth-child(2) {
		width: 200rpx;
		height: 72rpx;
		line-height: 72rpx;
		text-align: center;
		background: linear-gradient(90deg, #FA2222 2%, #FFC400 98%);
		border-radius: 40rpx;
		color: #ffffff;
	}
	.goback {
		position: absolute;
		left: 30rpx;
		text-align: center;
		width: 20rpx;
		height: 30rpx;
	}
</style>